package findPoisonedDuration;

public class Solution {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int res = 0;
        for (int i = 1; i < timeSeries.length; i++) {
            int time = timeSeries[i] - timeSeries[i-1]; // 这次攻击和上次攻击间隔的时间
            if(time<=duration){
                res+=time; //如果攻击间隔小于刷新的时间，就加上攻击间隔
            }else {
                res+=duration;
            }
        }
        return res;
    }
}
